﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace SECSendMsgService
{
    /// <summary>
    /// 读取config里面固定的内容
    /// </summary>
    public class SendMsgConfig
    {
        #region 属性

        #region 登入用户名
        /// <summary>
        /// 登入短信用户名
        /// </summary>
        protected string userName;
        public string UserName
        {
            get
            {
                return userName;
            }
        } 
        #endregion

        #region 登入密码
        /// <summary>
        /// 登入短信密码
        /// </summary>
        protected string password;
        public string Password
        {
            get
            {
                return password;
            }
        } 
        #endregion

        #region 发送时间列表
        /// <summary>
        /// 发送时间列表
        /// </summary>
        protected List<string> timeList;
        public List<string> TimeList
        {
            get
            {
                return timeList;
            }
        } 
        #endregion

        #region 测试收件人
       //测试收件人
       protected string testMsgTo;
       /// <summary>
       /// 测试收件人
       /// </summary>
       public string TestMsgTo
       {
           get { return testMsgTo; }
           set { testMsgTo = value; }
       } 
       #endregion

        #region 上次执行的时间
       //上一次执行的日期
       protected string gstrDateTime;
       /// <summary>
       /// 上一次执行的日期时间
       /// </summary>
       public string LastDateTime
       {
           get { return gstrDateTime; }
           set { gstrDateTime = value; }
       } 
       #endregion

        #region 短信标题
       /// <summary>
       /// 短信标题一般是短信开始部分
       /// </summary>
       public string MsgTitle { get; set; } 
       #endregion

        #endregion

        public SendMsgConfig(string path)
        {
            XMLHelper xh = new XMLHelper(path);
         
            //得到key
            string key=xh.GetSingleInnerTextByNodeName("/msgconfig/key");
            MySecurity ms = new MySecurity(key);
            File.AppendAllText("c:/1.txt", "key"+key);
            //初始化用户名和密码(解密处理)
            userName = ms.DecryptString(xh.GetSingleInnerTextByNodeName("/msgconfig/username"));
            File.AppendAllText("c:/1.txt", "username" + userName);
            password = ms.DecryptString(xh.GetSingleInnerTextByNodeName("/msgconfig/password"));
            File.AppendAllText("c:/1.txt", "password" +password );
            //初始化时间列表
            timeList = xh.GetListByNodeName("/msgconfig/msgset/emailtime/time");
            File.AppendAllText("c:/1.txt", "时间列表" + timeList.Count);
            //初始化测试收件人
            testMsgTo = xh.GetSingleInnerTextByNodeName("/msgconfig/testmsgto");
            File.AppendAllText("c:/1.txt", "testMsgTo" + testMsgTo);
            //初始化title
            MsgTitle = xh.GetSingleInnerTextByNodeName("/msgconfig/msgset/msgtitle");
            File.AppendAllText("c:/1.txt", "MsgTitle" + timeList);
        }

        

    }
}
